#ifndef CREGISTRATION_LIB_H_
#define CREGISTRATION_LIB_H_

#include "CRegistration.h"
#include <cstring>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
#include <sstream>

void Add_CRegis(string s, CRegistration l[], int &numberCRegistration){
   string s_id;
   int stu_id, l_id;
   string temp;

   int mark = s.find(":");
   s_id = s.substr(0,mark);;

   temp = s.substr(mark+1);
   mark = temp.find(":");
   l_id = atoi(temp.substr(0,mark).c_str());

   temp = temp.substr(mark+1);
   mark = temp.find(":");
   stu_id = atoi(temp.substr(0,mark).c_str());

   CRegistration CRe =  new(a_s_id, a_l_id, a_stu_id);
   l[numberCRegistration] = CRe;
   numberCRegistration = numberCRegistration + 1;
}
void ReadRegister(string _file, CRegistration l[], int &numberCRegistration){
               ifstream fin;
               fin.open(_file.c_str());
               if(!fin.is_open()){
                       cout<<"Cannot open file.\n";
                       exit(1);
               }else{
                              string s = "";
                              while (getline(fin, s)){
                                Add_CRegis(s,l,numberCRegistration);
                              }
                              fin.close();
               }
}

void WriteRegister(string _file, CRegistration l[], int &numberCRegistration){
               ofstream fout;
fout.open(_file.c_str());
               for (int i=0 ; i<numberCRegistration ; i++){
                              fout<<":"<<l[i].getLecturerID()<<":"<<l[i].getStudentID()<<":"<<l[i].getSubjectID()<<":"<<endl;
               }
               fout.close();
}

#endif


